//
//  WBNetWorkManager.swift
//  weibo
//
//  Created by shizb macbook air on 17/8/7.
//  Copyright © 2017年 YL. All rights reserved.
//

import UIKit
import AFNetworking

enum WZYRequestType {
    case Get
    case Post
}


class WBNetWorkManager: AFHTTPSessionManager {
    static let shareInstance:WBNetWorkManager={
        let toolInstance=WBNetWorkManager()
        
//        toolInstance.responseSerializer.acceptableContentTypes?.insert("text/html")
        return toolInstance
    }()
    func WBRequest(requestType:WZYRequestType,url:String,parameters:[String:Any],succeed:@escaping ([String:Any]?)->(),failure:@escaping (Error?)->()) {
        //成功的回调闭包
        let successBlock={
            (task:URLSessionDataTask,responseObj:Any?) in
            
            succeed(responseObj as? [String:Any])
        }
        //失败的回调闭包
        let failureBlock={
            (task:URLSessionDataTask?,error:Error) in
            failure(error)
            
        }
        
        // Get 请求
        if requestType == .Get {
            get(url, parameters: parameters, progress: nil, success: successBlock, failure: failureBlock)
        }
        
        // Post 请求
        if requestType == .Post {
            post(url, parameters: parameters, progress: nil, success: successBlock, failure: failureBlock)
        }
    }
    
}
























































